<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.stms.action.BaseQueryByUploadFileActionbean"%>
<%@page import="com.feib.stms.util.StmsUtil"%>
<%@page import="com.feib.stms.model.LabelValue"%>
<%@page import="com.feib.stms.util.UserUtil"%>

<%
// 欄位排序處理
BaseQueryByUploadFileActionbean actionBean = (BaseQueryByUploadFileActionbean) request.getAttribute("actionBean");
actionBean.setNavigator();
pageContext.setAttribute("actionBeanClassName", actionBean.getClass().getName());
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
        
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
    
    	$('#findGroupNoDiv').click(function() {
    		var url = '<c:url value="/Group.action"/>?qryGroup.groupNo=' + $('#qryUploadFile\\.group\\.groupNo').val();
    		var varOptions = 'help:no;status:no;scroll:yes;resize:yes;center:yes;dialogHeight:700px;dialogWidth:900px';
    		var dialogArguments = new Object();
    		dialogArguments.parentWindowObj = self;
    		dialogArguments.groupNoId = 'qryUploadFile.group.groupNo';
    		dialogArguments.groupPkId = 'qryUploadFile.group.groupPk';
    		dialogArguments.groupNameId = 'qryFormatDefinition.group.groupName.span';
    		dialogArguments.checkboxDiv = 'securitiesCheckBoxDiv';
    		var s = showModalDialog(url, dialogArguments, varOptions);

    		return true;				
		}); 
    
    	
    $("[id^='viewDetail-']").click(function() {
			var uploadFilePk = this.id.substring(11);
         	var url = '<c:url value="/Stms3005.action"/>?decorator=showModalDialogTemplate&confirm=true&doQueryWithSowModalDialog=&qryPymentFileContent.uploadFile.uploadFilePk='+uploadFilePk;
         	var varOptions = 'help:no;status:no;scroll:yes;resize:yes;center:yes;dialogHeight:700px;dialogWidth:1000px';
        	 var dialogArguments = new Object();
        	 dialogArguments.parentWindowObj = self;
         	var s1 = showModalDialog(url, dialogArguments, varOptions);
		 return true;                
        });
    	
    	$('#doQueryBtn').click(function() {
    		var qryDeliveryDateFrom = $('#qryDeliveryDateFrom').val();
    		var qryDeliveryDateTo = $('#qryDeliveryDateTo').val();
    		var groupPk = $('#qryUploadFile\\.group\\.groupPk').val();
    		var groupNo = $('#qryUploadFile\\.group\\.groupNo').val();
    		var errorMessage = '';
    		if (qryDeliveryDateFrom == '') errorMessage = '交割日期(起)不可空白!!';
    		if (qryDeliveryDateTo == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '交割日期(迄)不可空白!!';
    		}
    		
    		if (groupNo == '')
    		{
    		    if (errorMessage != '') errorMessage = errorMessage + '<br>';
    		    errorMessage = errorMessage + '券商代號不可空白!!';
    		}
            
            if (errorMessage != '')
            {
                showErrorMessageDialog(errorMessage);
                return false;
            }
            
    		return true;
				
		}); 
    	

 		//全選 
 		$('#checkboxAll').click(function() 
 		{
 			var chk = $('#checkboxAll').attr('checked');
 			$('#queryForm input:checkbox.qrychk').each(function(){
 				if("checked"==chk){
 					$(this).attr('checked', chk);
 				}
 				else
 				{
 					$(this).removeAttr('checked');
 				}
 			});
 		});
 		
 		$('#qryUploadFile\\.group\\.groupNo').change(function() {
 			$('#qryUploadFile\\.group\\.groupPk').val('');
 			$('#qryFormatDefinition\\.group\\.groupName\\.span').text('');
 			$('#securitiesCheckBoxDiv').html('');
		});

<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">

		$('#doExportExcelFileBtn').click(function() {
			$("#hidden\\.doExportExcelFileBtn").trigger('click');
		});
    	

		$("[id^='a-sortHeader-']").live("click", function() {
			var sortField = this.id.substring(13);
			$('#hidden\\.queryResult\\.sortCriterion').val(sortField);
			
			var clazz = $(this).attr('class');
			if (null == clazz || 0 == clazz.length)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else if ('sortAsc' == clazz)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else
				$('#hidden\\.queryResult\\.sortDirection').val('2');
				
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');			
			return false; <%// 此行一定要有，不然ie6不會執行submit%>
			
		});
		
		$("[id^='firstPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='prePageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${prePageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='nextPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${nextPageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='lastPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${lastPageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='currentPageText']").change(function() {
			var value = this.value;
			if (value != ''){
				value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				var intRegex = /^\d+$/;
				if(!intRegex.test(value)) {
					showErrorMessageDialog('頁數必須是整數');
					return ;
				}
				
				value = parseInt(value, 10);
				
				if (value < 1){
					showErrorMessageDialog('頁數必須是大於1');
					alert('');
					return ;
				}
				else if (value > <c:out value='${lastPageNumber}'/>){
					showErrorMessageDialog('頁數必須是小於總頁數 (<c:out value="${lastPageNumber}"/>)');
					return ;
				}
				else if (value != <c:out value='${currentPageNumber}'/>){
					doQueryAction();
					$('#hidden\\.queryResult\\.pageNumber').val(value);
					waitingDialog({});
					$("#hidden\\.doQueryBtn").trigger('click');
				}
				
			}
			else{
				showErrorMessageDialog('頁數不可為空白)');
				return ;
			}
		});
</c:if>
		
		
    	var dates = $( "#qryDeliveryDateFrom, #qryDeliveryDateTo" ).datepicker({
			defaultDate: "-1m",
			changeMonth: true,
			changeYear: true,
			numberOfMonths: 1,
			dateFormat: 'yy/mm/dd',
			showButtonPanel: true,
			showOn: "both",
			buttonImage: "<c:url value='styles/default/image/calendar.gif'/>",
			buttonImageOnly: true,
			onSelect: function( selectedDate ) {
				var option = this.id == "qryDeliveryDateFrom" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" );
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
    	
    	<c:if test="${not empty actionBean.message}">
    	showMessageDialog('<c:out value="${actionBean.message }" escapeXml="false"/>');
    	</c:if>
    	
    	<c:if test="${not empty actionBean.errorMessage}">
    	showErrorMessageDialog('<c:out value="${actionBean.errorMessage }" escapeXml="false"/>');
    	</c:if>
    	
	
                  
    });
    
   
    
    function doPrintEvent()
    {
    	divPrint('listForm');
    	return false;
    }
    
    //-->
    </script>
</head>
<body>
	
	<stripes:form id="queryUploadFileContentForm" beanclass="<%=actionBean.getClass().getName() %>" method="post" onsubmit="javascript: waitingDialog({});">	
	<div id="queryForm">
		<table>
			<tr>
				<td colspan="5" class="queryHeader">請輸入查詢條件</td>
			</tr>
			<%if ( UserUtil.isBankGroup()){ %>
			<tr>
				<th>券商代號<span id="mustKeyInStar">**</span></th>
				<td>
					<div id="findGroupNoDiv" class="widgetsIcon ui-state-default ui-corner-all" title="查詢券商"><span class="ui-icon ui-icon-zoomin"></span></div>
					<stripes:text id="qryUploadFile.group.groupNo" name="qryUploadFile.group.groupNo" size="12" maxlength="12" />
					<span id="qryFormatDefinition.group.groupName.span"><c:out value="${actionBean.qryUploadFile.group.groupName }"/></span>	
					<stripes:hidden id="qryUploadFile.group.groupPk" name="qryUploadFile.group.groupPk" />			
				</td>
			</tr>
			<%} else {%>
			<stripes:hidden id="qryUploadFile.group.groupNo" name="qryUploadFile.group.groupNo" />
			<stripes:hidden id="qryUploadFile.group.groupPk" name="qryUploadFile.group.groupPk" />
			<%} %>
			<tr>
				<th>上傳類別</th>
				<td colspan="4"><%=((LabelValue)StmsUtil.getInstance().getFileFormatMap().get(actionBean.getUploadFileFormat())).getLabel() %></td>
			</tr>
			<tr>
				<th>交割日期<span id="mustKeyInStar">**</span></th>
				<td colspan="4">
					<stripes:text id="qryDeliveryDateFrom" name="qryDeliveryDateFrom" size="10" maxlength="10" formatPattern="yyyy/MM/dd" readonly="true"/> ～  <stripes:text id="qryDeliveryDateTo" name="qryDeliveryDateTo" size="10" maxlength="10" formatPattern="yyyy/MM/dd" readonly="true"/>
				</td>
			</tr>
			<tr>
				<th>分公司<span id="mustKeyInStar">**</span></th>
				<td colspan="4">
					<input type="checkbox" name="checkboxAll" id="checkboxAll" value="全選"/>全選&nbsp;
					<div style="float:none;" id="securitiesCheckBoxDiv">				
					<c:forEach items="${actionBean.securities}" var="branchObj" varStatus="rowstat">
						<stripes:checkbox class="qrychk" id="qrySecuritiesNos[${rowstat.index}]" name="qrySecuritiesNos[${rowstat.index}]" value="${branchObj.securitiesNo}"/> <c:out value="${branchObj.securitiesName}" />&nbsp;
					</c:forEach>
					</div>
				</td>
			</tr>

			<tr>
				<td colspan="5" class="queryFunction"><input type="submit" id="doQueryBtn" value="查詢" name="doQuery" class="formBtn"/></td>
			</tr>
		</table>
	</div>
</stripes:form>

	
	<div id="queryForm"></div>
	
	<div id="listForm">
<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">

			<div id="paginationBar" style=" margin: 0 auto;">
			<input type="button" id="firstPageBtn" class="formBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" class="formBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" class="formBtn" value="${currentPageNumber }" size="3" maxlength="4" /> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" class="formBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" class="formBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />&nbsp;			
			</div>
                
                <table id="queryResultTable">
				<thead>
					<tr>
						
						<th><a id='a-sortHeader-fileName' href='javascript:void(0);' class="<c:out value='${fileNameSortedClass }'/>"> <c:out value='${fileNameSortedSpan }' escapeXml="false"/>檔案名稱</a> </th>						
						<th><a id='a-sortHeader-totalItems' href='javascript:void(0);' class="<c:out value='${totalItemsSortedClass }'/>"><c:out value='${totalItemsSortedSpan }' escapeXml="false"/>總筆數 </a></th>
                        <th><a id='a-sortHeader-totalNetIncome' href='javascript:void(0);' class="<c:out value='${totalNetIncomeSortedClass }'/>"><c:out value='${totalNetIncomeSortedSpan }' escapeXml="false"/>總淨收金額 </a></th>
                        <th><a id='a-sortHeader-totalNetPay' href='javascript:void(0);' class="<c:out value='${totalNetPaySortedClass }'/>"> <c:out value='${totalNetPaySortedSpan }' escapeXml="false"/>總淨付金額</a></th>
                        <th>明細</th>
                     </tr>
				</thead>
				<tbody>
                    <c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
                    <tr>
                         <td><c:out value="${viewObj.fileName }" /></td>
                        <td><c:out value="${viewObj.totalItems }" /></td>
                        <td align="right"><fmt:formatNumber value="${viewObj.totalNetIncome}" pattern="##,###" /></td>
                        <td align="right"><fmt:formatNumber value="${viewObj.totalNetPay}" pattern="##,###" /></td>
                     	<td>
                          <div id="viewDetail-<c:out value='${viewObj.uploadFilePk}'/>" class="widgetsIcon ui-state-default ui-corner-all" title="檢視"><span class="ui-icon ui-icon-circle-triangle-e"></span></div>
                        </td>
                    </tr>
                    </c:forEach>
                			</tbody>
				<tfoot>
					<tr>
						<td colspan="16" class="listFunction">
							<input type="button" value="列印" onclick="javascript:doPrintEvent();" class="formBtn"/>
				
						</td>
					</tr>
				</tfoot>
                </table>
</c:if>
	</div>
	
<div style="display: none;">
<stripes:form id="hidden.queryUploadFileContentForm" beanclass="<%=actionBean.getClass().getName() %>" method="post" >
	<stripes:hidden id="hidden.qryDeliveryDateFrom" name="qryDeliveryDateFrom" formatPattern="yyyy/MM/dd"/>	
	<stripes:hidden id="hidden.qryDeliveryDateTo" name="qryDeliveryDateTo" formatPattern="yyyy/MM/dd" />	
	<stripes:hidden id="hidden.qryUploadFile.group.groupPk" name="qryUploadFile.group.groupPk" />
	<stripes:hidden id="hidden.qryUploadFile.group.groupNo" name="qryUploadFile.group.groupNo" />
	<c:forEach items="${actionBean.qrySecuritiesNos}" var="qrySecuritiesNosObj" varStatus="rowstat">
		<stripes:text id="hidden.qrySecuritiesNos[${rowstat.index}]" name="qrySecuritiesNos[${rowstat.index}]" value="${qrySecuritiesNosObj}"/>
	</c:forEach>
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<stripes:submit id="hidden.doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
	<stripes:errors></stripes:errors>
</stripes:form>
</div>


</body>
</html>
